//
//  QuanYuXiaoXiTableViewCell.m
//  JuBoCRM
//
//  Created by iMac on 2024/12/10.
//  Copyright © 2024 iningKe. All rights reserved.
//

#import "QuanYuXiaoXiTableViewCell.h"
#import "NSDate+Helper.h"

#import "NSString+WPAttributedMarkup.h"
#import <CoreText/CoreText.h>
#import "NSDate+Helper.h"
#import "WPAttributedStyleAction.h"
#import "WPHotspotLabel.h"

@implementation QuanYuXiaoXiTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    _backImage.image = [self getResizableImage:LocalImagePath(@"chat_from_bg_normal")];
    
//    NSDictionary* style = @{@"black": rgba(40, 120, 255, 1),@"font":[UIFont systemFontOfSize:14]};
   
}

- (UIImage *)getResizableImage:(UIImage *)image{
    return [image resizableImageWithCapInsets:UIEdgeInsetsMake(image.size.height * 0.5, image.size.width * 0.5, image.size.height * 0.5, image.size.width * 0.5)];
}
- (void)setModel:(AllModel *)model{
    _model = model;
    NSDictionary *dataDic = model.modelInfoDictionary;
    NSDictionary* style = @{@"black": rgba(40, 120, 255, 1),@"font":[UIFont systemFontOfSize:14]};
    _timeLabel.text = [self huoQuShiJian:GetHandleString(dataDic, @"createTime")];
    
    _redView.hidden = [GetHandleString(dataDic, @"isRead") boolValue];
    _titleLabel.text = GetHandleString(dataDic, @"content");
    _nameLabel.text = GetHandleString(dataDic, @"customerName");
    if ([GetHandleString(dataDic, @"type") intValue] == 135 || [GetHandleString(dataDic, @"type") intValue] == 136){
        _nameLabel.hidden = NO;
        _nameReminLabel.hidden = NO;
        _chaKanButton.hidden = NO;
        _bottomSpace.constant = 64+30;
    }else{
        _chaKanButton.hidden = YES;
        _bottomSpace.constant = 16;
        _nameLabel.hidden = YES;
        _nameReminLabel.hidden = YES;
    }
    [self setupAutoHeightWithBottomView:_backView bottomMargin:8];
}

- (NSString *)huoQuShiJian:(NSString *)time{
    NSString *result = time;
    double timeRes = [[NSDate date] hoursLaterThan:[NSDate dateFromString:time withFormat:@"yyyy-MM-dd HH:mm:ss"]];
    if(timeRes > 0 && timeRes < 1){
        if([[NSDate date] minutesLaterThan:[NSDate dateFromString:time withFormat:@"yyyy-MM-dd HH:mm:ss"]] < 1){
            result = @"1分钟前";
        }else{
            result = [NSString stringWithFormat:@"%.0f分钟前",[[NSDate date] minutesLaterThan:[NSDate dateFromString:time withFormat:@"yyyy-MM-dd HH:mm:ss"]]];
        }
    }else if ([[NSDate dateFromString:time withFormat:@"yyyy-MM-dd HH:mm:ss"] isToday]){
        result = [NSDate dateStringFromString:time format:@"yyyy-MM-dd HH:mm:ss" toFormat:@"HH:mm"];
    }else{
        result = [NSDate dateStringFromString:time format:@"yyyy-MM-dd HH:mm:ss" toFormat:@"yyyy-MM-dd HH:mm"];
    }
    return result;
}
- (IBAction)click:(UIButton *)sender {
    if (_manageClickBlock) {
        _manageClickBlock(sender.tag);
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
